#ifndef _QFILT_H
#define _QFILT_H

#include "fixed.h"

#ifdef __cplusplus
extern "C" {
#endif


typedef struct {
	const fixedp *sos;		// array of filter coefficients (length 6*L)
	int sosFracbits;
	const fixedp *g;		// array of gain coeffs (length L)
	int gFracbits;
	fixedp *w;				// internal state (length 2*L)
	size_t L;				// the number of sections in the filter
} qfilt;

// Initialize a new filter object from its coefficients
// sos is the coefficients in SOS (secord order section) form
// that is, it is a 6*L array of values
// L is the number of 2nd order sections in the filter
// w should be a contiguous block of memory that the filter can use to store
// its data. It should be length 2*L
void qfilt_init(qfilt *f, const fixedp *sos, int sosFracbits, const fixedp *g, int gFracbits, fixedp *w, size_t L);

// Release all resources associated with the filter
void qfilt_free(qfilt *f);

// Compute output y for input x using Cascade Direct Form-II Transpose implementation
fixedp qfilt_filter(qfilt *f, fixedp x);

// Reset the state of the filter
void qfilt_reset(qfilt *f);

#ifdef __cplusplus
}	// extern C
#endif

#endif // _QFILT_H
